package com.banquetmanagementsystem.common.exception.advice;

import com.banquetmanagementsystem.common.exception.BaseException;
import com.banquetmanagementsystem.common.exception.LoginFailedException;
import com.banquetmanagementsystem.common.response.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一全局异常处理
 * @author 86176
 */
@RestControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(LoginFailedException.class)
    public Result<?> loginFailedException(LoginFailedException e){
        return Result.unauthorized(e.getMessage());
    }
    @ExceptionHandler(BaseException.class)
    public Result<?> baseException(BaseException e){
        return Result.failed(e.getMessage());
    }
}
